package com.campus.service.impl;

import com.campus.dao.CourseLearnUnitMapper;
import com.campus.entry.CourseLearnUnit;
import com.campus.pojo.dto.CourseLearnUnitDto;
import com.campus.pojo.dto.StudentLearningUnitDto;
import com.campus.service.CourseLearnUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseLearnUnitServiceImpl implements CourseLearnUnitService {

    @Autowired
    private CourseLearnUnitMapper courseLearnUnitMapper;

    @Override
    public List<CourseLearnUnitDto> getCourseLearnUnitsByTeacherId(int teacherId) {
        // 直接从 Mapper 层获取 CourseLearnUnitDto 列表
        return courseLearnUnitMapper.selectCourseLearnUnitsByTeacherId(teacherId);
    }

    @Override
    public List<CourseLearnUnitDto> getCourseLearnUnitsByTeacherId(int teacherId, String titleName, Integer status) {
        return  courseLearnUnitMapper.selectByConditions(teacherId,titleName,status);
    }

    @Override
    public void updateState(Integer id, Integer status) {
        courseLearnUnitMapper.updateState(id,status);
    }

    @Override
    public void deleteUnit(Integer id) {
        courseLearnUnitMapper.deleteById(id);
    }

    @Override
    public CourseLearnUnit getUnitById(Integer id) {
        return courseLearnUnitMapper.selectById(id);
    }

    @Override
    public void updateUnit(CourseLearnUnit courseLearnUnit) {
        courseLearnUnitMapper.updateById(courseLearnUnit);
    }

    @Override
    public void saveUnit(CourseLearnUnit courseLearnUnit) {
        courseLearnUnitMapper.insert(courseLearnUnit);
    }

    @Override
    public List<StudentLearningUnitDto> getUnitByStudent(Integer studentId) {
        return courseLearnUnitMapper.getLearningUnitsByStudentId(studentId);
    }
}
